package pl.enigmatic.math;

import java.util.List;


/**
 * Represents a bijection mapping from integers to <code>Y</code> - an identity sequence of <code>Y</code>s.
 * @author reggie_7
 * @param <Y> type of values in the sequence
 */
public class BijectionSequence<Y> extends BijectionMap<Integer, Y> {

	/** Default constructor. The map created will be empty. */
	public BijectionSequence() {}

	/**
	 * Constructs a sequence initialized with the given <code>values</code>. If the <code>values</code> are not distinct the result is not specified.
	 * @param values created sequence values
	 */
	public BijectionSequence(final Y... values) {
		int x = 0;
		for (final Y y : values) {
			putXY(x++, y);
		}
	}

	/**
	 * Returns an array of indexes for the given <code>ys</code> values.
	 * @param ys values to convert to integers
	 * @return an array of indexes for the given <code>ys</code> values
	 */
	public int[] getIndexes(final Y... ys) {
		final List<Integer> list = super.convertY(ys);
		final int[] res = new int[list.size()];
		final Object array[] = list.toArray();
		for (int i = 0; i < res.length; i++) {
			res[i] = (Integer) array[i];
		}
		return res;
	}

}
